
*------------------------------------------------------------------------------*
* Government position weighted by number of cabinet members
*
* Additional specs:
*	1. Excluding NONAs and parties with missing ideology
*	2. Fallback: 1st chamber median for expert governments
*
* Version:	2016-06-10
* Changes:	2016-??-??: First release
*------------------------------------------------------------------------------*


* Exclude NONAs and parties with missing ideology
gen filtermin = p107 if p103 == 1 & $ideology != .
by g101 g105, sort: egen newsummin = sum(filtermin)
gen newpofmin = (filtermin / newsummin * 100)

* Weigh new p% of cabinet members with ideology
gen zs1 = ($ideology * newpofmin) / 100

* Aggregate
by g101 g105, sort: egen GOV_POS = sum(zs1)
save zs, replace


* Fill in GOV_POS with fallback
replace GOV_POS = median1st if newsummin == 0 & GOV_POS == 0


* Cleansing
replace GOV_POS = . if g106 == 9

lab var GOV_POS "Position of government"

sort g101 g105 p101

capture: drop zs* filtermin newsummin newpofmin 
capture: erase zs.dta
capture: erase zs_median.dta
